package com.gen.controller;

import javax.servlet.http.HttpServletRequest;

import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.gen.service.ILikeService;
import com.zzx.entity.Like;

@Controller
public class LikeController {
	@Autowired
	private ILikeService likeService;
	
	@RequestMapping("/details.do")
	public ModelAndView selectLikeFromLikeByPid(HttpServletRequest request) {
		Integer pid = Integer.parseInt(request.getParameter("pid"));
		ModelAndView modelAndView = new ModelAndView();
		Like like = likeService.selectLikeFromLikeByPid(pid);
		request.setAttribute("pid", pid);
		modelAndView.addObject("like", like);
		modelAndView.setViewName("details");
		return modelAndView;
	}
	@RequestMapping("/updateLikeGoodsPlusOne.do")
	@ResponseBody
	public int updateLikeGoodsPlusOne(@Param("pid") Integer pid) {
		int result = likeService.updateLikeGoodsPlusOne(pid);
		return result;
	}
	@RequestMapping("/updateLikeGoodsReduceOne.do")
	@ResponseBody
	public int updateLikeGoodsReduceOne(@Param("pid") Integer pid) {
		int result = likeService.updateLikeGoodsReduceOne(pid);
		return result;
	}
	@RequestMapping("/selectCountByPid.do")
	@ResponseBody
	public Integer selectCountByPid(@PathVariable("pid") Integer pid) {
		Integer count = likeService.selectCountByPid(pid);
		return count;
	}
	
}
